nlp_architect.models.matchlstm_ansptr.MatchLSTMAnswerPointer¶
-
class
nlp_architect.models.matchlstm_ansptr.
MatchLSTMAnswerPointer
(params_dict, embeddings)[source]¶ Defines end to end MatchLSTM and Answer_Pointer network for Reading Comprehension
-
__init__
(params_dict, embeddings)[source]¶ Parameters: - params_dict – Dictionary containing the following keys- ‘max_question’ : max length of all questions in the dataset ‘max_para’ : max length of all paragraphs in the dataset ‘hidden_size’: number of hidden units in the network ‘batch_size’ : batch size defined by user
- embeddings – Glove pretrained embedding matrix
Methods
__init__
(params_dict, embeddings)param params_dict: Dictionary containing the following keys- answer_pointer_pass
()Function to run the answer pointer pass: cal_f1_score
(ground_truths, predictions)Function to calculate F-1 and EM scores create_model
()Function to set up the end 2 end reading comprehension model create_variables
()Function to create variables used for training get_dynamic_feed_params
(question_str, …)Function to get required feed_dict format for user entered questions. inference_mode
(session, valid, vocab_tuple, …)Function to run inference_mode for reading comprehension obtain_indices
(preds_start, preds_end)Function to get answer indices given the predictions run_loop
(session, train[, mode, dropout])Function to run training/validation loop and display training loss, F1 & EM scores unroll_with_attention
([reverse])Function to run the match_lstm pass in both forward and reverse directions -
answer_pointer_pass
()[source]¶ Function to run the answer pointer pass:
Parameters: None – Returns: List of logits for start and end indices of the answer
-
cal_f1_score
(ground_truths, predictions)[source]¶ Function to calculate F-1 and EM scores
Parameters: - ground_truths – labels given in the dataset
- predictions – logits predicted by the network
Returns: F1 score and Exact-Match score
-
get_dynamic_feed_params
(question_str, vocab_reverse)[source]¶ Function to get required feed_dict format for user entered questions. Used mainly in the demo mode.
Parameters: - question_str – question string
- vocab_reverse – vocab dictionary with words as keys and indices as values
Returns: list of indicies represnting the question padded to max length question_len: actual length of the question ques_mask: mask for question_idx
Return type: question_idx
-
inference_mode
(session, valid, vocab_tuple, num_examples, dropout=1.0, dynamic_question_mode=False, dynamic_usr_question='', dynamic_question_index=0)[source]¶ Function to run inference_mode for reading comprehension
Parameters: - session – tensorflow session
- valid – data dictionary for validation set
- vocab_tuple – a tuple containing voacab dictionaries in forward and reverse directions
- num_examples – specify the number of samples to run for inference
- dropout – Float value which is always 1.0 for inference
- dynamic_question_mode – boolean to enable whether or not accept questions from the user(used in the demo mode)
-
static
obtain_indices
(preds_start, preds_end)[source]¶ Function to get answer indices given the predictions
Parameters: - preds_start – predicted start indices
- predictions – predicted end indices
Returns: final start and end indices for the answer
-